﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Caching;
namespace ECommerce.DAO.Cache.Productos
{
    public static class Familia
    {
        public static ECommerce.Model.Productos.Familia GetFamiliaById(Int32 Id)
        {
            ECommerce.Model.Productos.Familia Familia = new ECommerce.Model.Productos.Familia();
            try
            {
                Familia = (ECommerce.Model.Productos.Familia)HttpRuntime.Cache["Familia-" + Id];
            }
            catch (Exception ex)
            {
                Familia = null;
            }
            if (Familia!=null && Familia.Id == 0)
                Familia = null;
            return Familia;
        }
        public static int SetFamilia(ECommerce.Model.Productos.Familia Familia)
        {
            int result = 0;
            try
            {
                HttpRuntime.Cache.Insert("Familia-" + Familia.Id.ToString(), Familia);
            }
            catch (Exception ex)
            {
            }
            return Familia.Id;
        }
        public static int DelFamilia(ECommerce.Model.Productos.Familia Familia)
        {
            int result = 0;
            try
            {
                HttpRuntime.Cache.Remove("Familia-" + Familia.Id.ToString());
            }
            catch (Exception ex)
            {
            }
            return Familia.Id;
        }


        public static ECommerce.Model.Productos.Familia[] GetFamiliasHijas(int IdFamilia)
        {
            ECommerce.Model.Productos.Familia[] Familias;
            try
            {
                Familias = (ECommerce.Model.Productos.Familia[])HttpRuntime.Cache["FamiliasHijas-" + IdFamilia.ToString()];
            }
            catch (Exception ex)
            {
                Familias = null;
            }
            if (Familias != null)
                if (Familias.Length == 0)
                    Familias = null;
            return Familias;
        }

        public static int SetFamiliasHijas(ECommerce.Model.Productos.Familia[] FamiliasHijas, int IdFamilia)
        {
            try
            {
                HttpRuntime.Cache.Insert("FamiliasHijas-" + IdFamilia.ToString(), FamiliasHijas);
            }
            catch (Exception ex)
            {
            }
            return IdFamilia;
        }
        public static int DelFamiliasHijas(int IdFamilia)
        {
            try
            {
                HttpRuntime.Cache.Remove("FamiliasHijas-" + IdFamilia.ToString());
            }
            catch (Exception ex)
            {
            }
            return IdFamilia;
        }

        public static ECommerce.Model.Productos.Familia[] GetFamiliasByIdProducto(int Id)
        {
            ECommerce.Model.Productos.Familia[] Familias;
            try
            {
                Familias = (ECommerce.Model.Productos.Familia[])HttpRuntime.Cache["FamiliasByIdProducto-" + Id];
            }
            catch (Exception ex)
            {
                Familias = null;
            }
            if (Familias != null && Familias.Length == 0)
                Familias = null;
            return Familias;
        }

        public static ECommerce.Model.Productos.Familia[] GetFamiliasByCatálogoId(int ident)
        {
            throw new NotImplementedException();
        }
    }
}
